package Collection_etc;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/3/20 22:15
 * 说明：foreach 增强for循环
 */

public class ForEachTest {
    @Test
    public void test1(){
        Collection coll = new ArrayList();

        coll.add("AA");
        coll.add("AA");
        coll.add(123); // 基本数据类型：自动装箱
        coll.add("下硅谷");
        coll.add(new Person("Jimmy", 24));

        for (Object obj : coll) {
            System.out.println(obj);
        }
    }

    @Test
    public void test2() {
        int sum = 0;
        int[] arr = {1, 2, 3, 4, 6, 8, 6, 1 ,3 ,8 , 464, 1654};
        for (int i : arr) {
            sum += i;
        }
        System.out.println(sum);
    }

    // 底层实现还是集合的迭代器
    @Test
    public void test3() {
        String[] arr = {"asd", "rgd", "tyre"};
        for (String s : arr) {
            System.out.println(s);
        }
    }
}
